package com.hzw.code

import androidx.lifecycle.MutableLiveData
import com.hzw.code.api.Api
import com.hzw.code.api.WorkspaceApi
import com.hzw.code.bean.Consultation
import com.hzw.code.bean.Detail
import com.hzw.code.extend.convertJsonRequestBody
import com.hzw.code.net.HttpManager
import com.hzw.code.vm.AbsViewModel
import com.safframework.log.L

/**
 *
 * @Author:         HuaZhongWei
 * @CreateDate:     2020/4/20 15:22
 *
 * @Description:
 *
 */
class NormalViewModel : AbsViewModel() {

    val workspaceApi = HttpManager.getApi<WorkspaceApi>(
        WorkspaceApi::class.java
    )

    val api = HttpManager.getApi<Api>(
        Api::class.java
    )

    val workspaceLiveData: MutableLiveData<Consultation> = MutableLiveData()
    val patientDetailLiveData: MutableLiveData<Detail> = MutableLiveData()


    fun loadConsultationList() {
        launchUI {
            showLoading()
            val workspace =
                workspaceApi.loadConsultationList(
                    convertJsonRequestBody(
                        "consultationStatus" to 2,
                        "page" to 1,
                        "limit" to 20
                    )
                )
            workspaceLiveData.value = workspace.data
            L.i("workspace = $workspace")
//            hideLoading()
//            showContent()
            showError()
        }
    }

    fun fetchPatientDetail() {
        launchUI {
            showLoading()
            val fetchPatientDetail = api.fetchPatientDetail(convertJsonRequestBody("patientUnionId" to "3878528916247760735"))
            L.i("fetchPatientDetail = $fetchPatientDetail")
            patientDetailLiveData.value = fetchPatientDetail.data
//            hideLoading()
//            showContent()
            showEmpty()
        }
    }
}